﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestWebApplication.CommerceAccount;
using Microsoft.Commerce.Proxy.AccountService;
using TestWebApplication.CommerceTestDataProvider;

namespace WebParts
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Write("aaa");

        }

        protected void createAccount_Click(object sender, EventArgs e)
        {
            /*String CommerceAccountServiceUrl = (String)Application["CommerceAccountServiceUrl"];
            //Response.Write(CommerceAccountServiceUrl);
            String CertLocation = (String)Application["Certlocation"];
            CommerceAccountServiceAccessor accountService = new CommerceAccountServiceAccessor(CommerceAccountServiceUrl, CertLocation);
            accountService.Initialize();

            Identity requester = CommerceAccountDataProvider.CreateRandomIdentity();
            CallerInfo callerInfo = CommerceAccountDataProvider.CreateCallerInfo(requester, null);

            Microsoft.Commerce.Proxy.AccountService.AccountInfo accountInfo = new Microsoft.Commerce.Proxy.AccountService.AccountInfo();
            accountInfo.PayinInfo = new PayinAccountInfo()
            {
                CountryCode = country.Text,
                Currency = currency.Text,
                CustomerType = CustomerType.Personal,
                FriendlyName = name.Text,
                Locale = locale.Text,
                LastName = lastName.Text,
                FirstName = firstName.Text,
                Email = email.Text,
            };

            Address address = new Address();
            address.FriendlyName = friendlyName.Text;
            address.Street1 = street.Text;
            address.UnitNumber = GlobalRandom.Next(2000).ToString();
            address.City = city.Text;
            address.District = disctrict.Text;
            address.State = state.Text;
            address.CountryCode = country.Text;
            address.PostalCode = postalCode.Text;
            accountInfo.PayinInfo.AddressSet = new Address[] { address };

            CommerceUserAccount account = accountService.CreateAccount(callerInfo, accountInfo);
           
            Session["accountID"] = account.AccountInfo.AccountID;
            Session["requester"] = requester;

            Response.Redirect("Login.aspx");*/
        }
    }
}
